unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, StdCtrls, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdHTTP, PerlRegEx;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    IdHTTP1: TIdHTTP;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Memo1: TMemo;
    procedure WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
const
  C_URL='http://video.shishicai.cn/haoma/cqssc/list/120.aspx';  

implementation



{$R *.dfm}

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
var
  Doc:Variant;
begin
  Doc:=WebBrowser1.Document;
  Writeln(Doc.body.innerhtml);
  
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Self.WebBrowser1.Navigate(C_URL);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  WebContext:string;
  StrStrm   :TStringStream;
  Strs      :TStringList;
begin
  idHttp1.Request.AcceptCharSet:='UTF-8';
//  WebContext:=IdHTTP1.Get('http://www.zhubajie.com/listbid-e-5.html',StrStrm);
  StrStrm:=TStringStream.Create('');
  IdHTTP1.Get(C_URL,StrStrm);

//  if IdHTTP1.WriteLn();
  Writeln(UTF8Decode(StrStrm.DataString));

  Strs:=TStringList.Create;

  Strs.Add(UTF8Decode(StrStrm.DataString));
  Strs.SaveToFile('1.txt');


  

end;

procedure TForm1.Button3Click(Sender: TObject);
var
  Regex:TPerlRegEx;
  StrsA:TStringList;
  TempA:string;
  IdexA:Integer;
begin
  Regex:=TPerlRegEx.Create(nil);

  StrsA:=TStringList.Create;
  StrsA.LoadFromFile('1.txt');

  TempA:=StrsA.Text;
  Regex.Subject:=TempA;
  //Regex.RegEx  :='<table .* /<//table/>';
  //Regex.RegEx:='\<table .*>(.*) <\/table>';      //
  //Regex.RegEx:='<table.*?>(.*)';
//  Regex.RegEx:='<table.*?>';
  Regex.RegEx:='.*?</table>';
  //Regex.RegEx:='<table(\S*?)[^>]*>.*?</\1>|<.*? />';

//  IdexA:=Pos('<table',TempA);
//  ShowMessageFmt('%d',[IdexA]);
//  TempA:=Copy(TempA,IdexA-1,MaxInt);
//  StrsA.Clear;
//  StrsA.Add(TempA);
//  StrsA.SaveToFile('2.txt');
//  if Regex.Match then
  while Regex.MatchAgain do
  begin
    ShowMessage('true');  
    Writeln(Regex.MatchedExpression);
  end;


  FreeAndNil(Regex);
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  StrsA:TStringList;
  Regex:TPerlRegEx;
  TempA:string;
begin
  StrsA:=TStringList.Create;
  Regex:=TPerlRegEx.Create(nil);

  StrsA.LoadFromFile('1.txt');
  TempA:=StrsA.Text;

  StringReplace(TempA,' ','',[rfReplaceAll]);
  Memo1.Clear;
  Memo1.Text:=TempA;


end;

end.
